import processing.core.*;

public class graphData {
	
	int rowCount;
	String[] rowNames;
	int columnCount;
	String[] columnNames;
	float[][] data;
	
	graphData(String filename){
		
		String[] rows = GLOBAL.processing.loadStrings(filename);		
		String[] columns = PApplet.split(rows[0],'	');
	    columnNames = PApplet.subset(columns, 0); //only for determining number of columns	    
	    columnCount = columnNames.length; 
	    rowNames = new String[rows.length];
	    data = new float[rows.length][];
	    rowCount = 0; 
	    
	    for (int i = 0; i < rows.length; i++) {
	    	String[] pieces = PApplet.split(rows[i], '	');
	    	data[rowCount] = PApplet.parseFloat(PApplet.subset(pieces, 0, 2));
	    	rowCount++;      	    	
	    }
	    data = (float[][]) PApplet.subset(data, 0, rowCount);
	}
	
	float getXCoord(int rowIndex){
		return data[rowIndex][0];
	}
	
	float getYCoord(int rowIndex){
		return data[rowIndex][1];
	}
	int getRowCount() {
	    return rowCount;
	}
	
	float getXMin() {
	    float m = Float.MAX_VALUE;
	    for (int row = 0; row < rowCount; row++) {        
	         if (data[row][0] < m) {
	           m = data[row][0];
	         }	      
	    }
	    return m;
	}
	
	float getYMin() {
	    float m = Float.MAX_VALUE;
	    for (int row = 0; row < rowCount; row++) {        
	         if (data[row][1] < m) {
	           m = data[row][1];
	         }	      
	    }
	    return m;
	}
	
	float getXMax() {
	    float m = -Float.MAX_VALUE;
	    for (int row = 0; row < rowCount; row++) {	              
	          if (data[row][0] > m) {
	            m = data[row][0];
	          }   	      
	    }
	    return m;
	  }
	
	float getYMax() {
	    float m = -Float.MAX_VALUE;
	    for (int row = 0; row < rowCount; row++) {	              
	          if (data[row][1] > m) {
	            m = data[row][1];
	          }   	      
	    }
	    return m;
	  }
}

